const COS = require('cos-nodejs-sdk-v5');
const path = require('path');
const { loadEnv } =require('vite')
const env = loadEnv('',path.resolve(__dirname,'../'),'')
const cos = new COS({
  SecretId: env.SecretId,
  SecretKey: env.SecretKey,
});

//单个文件上传
exports.uploadFile = async function (localPath, cosFileName) {
  return new Promise((resolve, reject) => {
    cos.uploadFile(
      {
        /** 要上传的本地文件路径 */
        FilePath: localPath,
        Bucket: env.Bucket,
        Region: env.Region,
        Key: cosFileName.replace(/\\/ig,'/'),
      },
      function (err, data) {
        if (err) {
          reject(err);
        } else {
          resolve(data);
        }
      },
    );
  });
};
